# FILE: DateFactory.py
# DESC: Factory implementation for Date objects.

from EntityFactory import EntityFactory
from web.entity.Date import Date 
from infra.logging import logger

class DateFactory(EntityFactory):

	def __init__(self, dataFilters):
		EntityFactory.__init__(self)
		self.dataFilters_ = dataFilters
		self.data_ = None 


	def validate(self, argv):
		log = logger.getLogger()
		rv = True
		data = argv
		for dataFilter in self.dataFilters_:
			data = dataFilter.filter(data)
		if not data:
			self.errMsg_ = "All data filtered out. DateFactory has nothing to work with."
			log.warning(self.errMsg_)
			rv = False
		else:
			self.data_ = data
		return rv 


	def doCreateEntity(self, consumer, relevanceFactor):
		date = Date(self.data_)
		if consumer:
			consumer.onDate(date)
		return date


	def getEntityType(self):
		return ('([0-9]+\s+)'
                '((J|j)an(uary)?|'
                '(F|f)eb(ruary)?|' 
                '(M|m)ar(ch)?|' 
                '(A|a)pr(il)?|' 
                '(M|m)ay|'
                '(J|j)un|'
                '(J|j)ul(y)?|'
                '(A|a)ug(ust)?|'
                '(S|s)ep(tember)?|'
                '(O|o)ct(ober)?|'
                '(N|n)ov(ember)?|'
                '(D|d)ec(ember))'
                '($|\s+)')
